import Vue from 'vue'
import VueRouter from 'vue-router'
import main from '@/views/main.vue'
import home from '@/views/home'
import login from '@/views/login'
import loginH4a from '@/views/login/loginH4a'

import settings from '@/settings'

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)
// * 例子：http://192.168.0.40/confluence/pages/viewpage.action?pageId=61576962#heading-23%E8%B7%AF%E7%94%B1%E5%8F%8A%E6%9C%AC%E5%9C%B0%E8%8F%9C%E5%8D%95
const routes = [
  {
    path: '/',
    name: 'ep',
    redirect: settings.stickyMenuPath || '/home',
    component: main,
    meta: {
      title: '首页'
    },
    /**
     * 正常布局内的页面定义在这里
     * meta参数说明:
     *    title-标签页标题，
     *    keepAlive-是否缓存页面 默认为true
     *    closeable-标签页是否能古关闭 默认为true (/home特殊处理的)
     *    multi 是否开启多页面，默认为 false
     *    multiKey: 'id', // 同多页面的 /:id 保持一致，默认为“id”
     *    name 不能重复
     *    name 不能重复
     *    name 不能重复
     */
    children: [
      // “微前端”页面 非必要请勿改动 -- start
      {
        path: '/chunk/:route',
        name: 'chunk',
        component: () => import(/* webpackChunkName: "chunk" */ '@easipass/chunk-render/views'),
        meta: {
          title: 'chunk页面',
          chunk: true
        }
      },
      {
        path: '/chunk/:route/:id',
        name: 'chunkMulti',
        component: () => import(/* webpackChunkName: "chunkmulti" */ '@easipass/chunk-render/views'),
        meta: {
          title: 'chunkd多页面',
          chunk: true,
          multi: true
          // multiKey: 'id',
        }
      },
      // “微前端”页面 非必要请勿改动 -- end
      {
        path: '/home',
        name: 'home',
        component: home,
        meta: {
          title: '首页'
        }
      },
      // #EPFC-demo-start
      {
        path: '/basic-table',
        name: 'basic-table',
        component: () => import(/* webpackChunkName: "basic-table */ '@/views/demo/basic-table'),
        meta: {
          title: 'Demo页面-基础查询'
        }
      },
      {
        path: '/demo-1',
        name: 'demo-1',
        component: () => import(/* webpackChunkName: "demo-1" */ '@/views/demo/demo-1'),
        meta: {
          title: 'Demo页面-1'
        }
      },
      {
        path: '/demo-chunk',
        name: 'demo-chunk',
        component: () => import(/* webpackChunkName: "demo-chunk" */ '@/views/demo/demo-chunk'),
        meta: {
          title: 'Demo页面-1'
        }
      },
      {
        path: '/search-1',
        name: 'search-1',
        component: () => import(/* webpackChunkName: "search-1" */ '@/views/demo/search-1'),
        meta: {
          title: 'Search页面-1'
        }
      },
      {
        path: '/search-2',
        name: 'search-2',
        component: () => import(/* webpackChunkName: "search-2" */ '@/views/demo/search-2'),
        meta: {
          title: 'Search页面-2'
        }
      },
      {
        path: '/search-3',
        name: 'search-3',
        component: () => import(/* webpackChunkName: "search-3" */ '@/views/demo/search-3'),
        meta: {
          title: 'Search页面-3'
        }
      },
      {
        path: '/form-1',
        name: 'form-1',
        component: () => import(/* webpackChunkName: "form-3" */ '@/views/demo/form-1'),
        meta: {
          title: 'Form页面-3'
        }
      },

      // #EPFC-wujie-end
      // #EPFC-demo-end
      // #EPFC-microapp-start
      // 多页面是微前端的例子
      // {
      //   path: '/microAppMulti/page',
      //   name: 'microAppMultiCreate',
      //   component: () => import(/* webpackChunkName: "multiPageDemo" */ '@/views/demo/microApp/page1'),
      //   meta: {
      //     title: '微服务详情页-新建',
      //   },
      // },
      // {
      //   path: '/microAppMulti/page/:id',
      //   name: 'microAppMultiDetail',
      //   component: () => import(/* webpackChunkName: "multiPageDemo" */ '@/views/demo/microApp/page1'),
      //   meta: {
      //     title: '微服务详情页',
      //     multi: true,
      //   },
      // },
      // #EPFC-microapp-end
      // #EPFC-microapp-start
      // {
      //   path: '/test',
      //   name: 'test',
      //   component: test,
      //   meta: {
      //     title: '示例',
      //     keepAlive: true,
      //     closeable: true
      //      // multiKey: 'id',
      //   },
      // },
      // {
      //   // 👇 非严格匹配，/child-app/* 都指向 MyPage 页面
      //   path: '/child-app',
      //   name: 'child-app',
      //   component: () => import(/* webpackChunkName: "multiPageDemo" */ '@/views/myPage'),
      //   // redirect: '/child-app/app1',
      //   meta: {
      //     title: '微前端页面',
      //     microApp: true,
      //   },
      //   children: [
      //     {
      //       path: 'app1/:id?',
      //       component: () => import(/* webpackChunkName: "multiPageDemo" */ '@/views/myPage'),
      //     },
      //     {
      //       path: 'app2/:id?',
      //       component: () => import(/* webpackChunkName: "multiPageDemo" */ '@/views/myPage'),
      //     },
      //     {
      //       path: 'app3/:id?',
      //       component: () => import(/* webpackChunkName: "multiPageDemo" */ '@/views/myPage'),

      //     }
      //   ]
      // },
      // #EPFC-microapp-end
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: login
  },
  {
    path: '/login_h4a',
    name: 'H4a登录',
    component: loginH4a
  },
  {
    path: '/about',
    name: 'about',
    component: () => import(/* webpackChunkName: "about" */ '@/views/about.vue')
  },
  {
    path: '/401',
    name: '401',
    component: () => import(/* webpackChunkName: "401" */ '@/views/401.vue')
  },
  {
    path: '*',
    name: '404',
    component: () => import(/* webpackChunkName: "404" */ '@/views/404.vue')
  }
]

const router = new VueRouter({
  routes
})

export default router
